package org.example.algorithm.bst;

import org.example.algorithm.TreeNode;

public class SortedArrayToBSTSolution {

    public static void main(String[] args) {
        int[] nums = {-10,-3,0,5,9};
    }

    public TreeNode sortedArrayToBST(int[] nums) {
        if (nums == null || nums.length == 0) {
            return null;
        }
        return doTrans(nums, 0, nums.length-1);
    }

    private TreeNode doTrans(int[] nums, int start, int end) {
        if (start > end) {
            return null;
        }
        int middle = (start + end) / 2;
        TreeNode node = new TreeNode(nums[middle]);
        node.left = doTrans(nums, start, middle-1);
        node.right = doTrans(nums, middle+1, end);
        return node;
    }
}
